﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web;
using System.Reflection;
using CustomMVC.Extensions;
using System.Diagnostics;

namespace CustomMVC
{
    public class ErrorOper : ActionFilterAttribute, IExceptionFilter
    {
        public ErrorOper()
        {
            Order = 2;
        }

        public void OnException(ExceptionContext filterContext)
        {
            Trace.WriteLine(DateTime.Now + filterContext.Exception.Message + "\n\r");
            RequestResult result=new RequestResult();
            result.Result="Fail";
            result.Message=filterContext.Exception.Message;
            HttpResponseBase response = filterContext.HttpContext.Response;
            response.ContentType = "application/json";
            response.Write(result.toJson());
            filterContext.ExceptionHandled = true;
        }
    }
}
